/**
 * 删除链表的节点
 * @param head 
 * @param val 
 */
const deleteNode = (head: ListNode | null, val: number): ListNode | null => {
    // 边界判断
    if (head === null) return null

    // 删除的是头节点
    if (head.val == val) return head.next;

    // 删除的不是头节点
    let prev = head,
        root = head;
    while (head !== null) {
        if (head.val === val) {
            if (head.next !== null) {
                // 不是尾节点
                head.val = head.next.val
                head.next = head.next.next;
            } else {
                // 前一个节点指向空即可
                prev.next = null
            }
            break;
        }
        prev = head;
        head = head.next;
    }
    return root
};